package com.android.jingweiapp.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.jingweiapp.R;
import com.android.jingweiapp.fragment.information.AnnounceNewsFragment;
import com.android.jingweiapp.fragment.information.HomeNewsFragment;
import com.android.jingweiapp.fragment.information.ImportantNewsFragment;
import com.android.jingweiapp.fragment.information.JXDynamicFragment;
import com.android.jingweiapp.fragment.information.NotifyNewsFragment;
import com.android.jingweiapp.fragment.information.PictureNewsFragment;
import com.android.jingweiapp.fragment.information.QWDynamicFragment;
import com.android.jingweiapp.fragment.information.VideoNewsFragment;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 资讯
 */
public class InformationFragment extends Fragment {

    @Bind(R.id.tab_information_0)
    TextView tabInformation0;
    @Bind(R.id.tab_information_1)
    TextView tabInformation1;
    @Bind(R.id.tab_information_2)
    TextView tabInformation2;
    @Bind(R.id.tab_information_3)
    TextView tabInformation3;
    @Bind(R.id.tab_information_4)
    TextView tabInformation4;
    @Bind(R.id.tab_information_5)
    TextView tabInformation5;
    @Bind(R.id.tab_information_6)
    TextView tabInformation6;
    @Bind(R.id.tab_information_7)
    TextView tabInformation7;


    private HomeNewsFragment homeNewsFragment;
    private ImportantNewsFragment importantNewsFragment;
    private JXDynamicFragment jxDynamicFragment;
    private PictureNewsFragment pictureNewsFragment;
    private QWDynamicFragment qwDynamicFragment;
    private VideoNewsFragment videoNewsFragment;
    private NotifyNewsFragment notifyNewsFragment;
    private AnnounceNewsFragment announceNewsFragment;

    public InformationFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_information, container, false);
        ButterKnife.bind(this, view);
        init();
        return view;
    }


    public void init() {
        homeNewsFragment = new HomeNewsFragment();
        pictureNewsFragment = new PictureNewsFragment();
        qwDynamicFragment = new QWDynamicFragment();
        jxDynamicFragment = new JXDynamicFragment();
        importantNewsFragment = new ImportantNewsFragment();
        videoNewsFragment = new VideoNewsFragment();
        notifyNewsFragment = new NotifyNewsFragment();
        announceNewsFragment = new AnnounceNewsFragment();

        getChildFragmentManager().beginTransaction()
                .replace(R.id.ly_information_container, homeNewsFragment)
                .commit();

        tabInformation0.setSelected(true);

        tabInformation0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!tabInformation0.isSelected()) {
                    getChildFragmentManager().beginTransaction()
                            .replace(R.id.ly_information_container, homeNewsFragment)
                            .commit();
                    tabInformation0.setSelected(true);
                    tabInformation1.setSelected(false);
                    tabInformation2.setSelected(false);
                    tabInformation3.setSelected(false);
                    tabInformation4.setSelected(false);
                    tabInformation5.setSelected(false);
                    tabInformation6.setSelected(false);
                    tabInformation7.setSelected(false);
                }
            }
        });

        tabInformation1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!tabInformation1.isSelected()) {
                    getChildFragmentManager().beginTransaction()
                            .replace(R.id.ly_information_container, importantNewsFragment)
                            .commit();
                    tabInformation0.setSelected(false);
                    tabInformation1.setSelected(true);
                    tabInformation2.setSelected(false);
                    tabInformation3.setSelected(false);
                    tabInformation4.setSelected(false);
                    tabInformation5.setSelected(false);
                    tabInformation6.setSelected(false);
                    tabInformation7.setSelected(false);
                }
            }
        });

        tabInformation2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!tabInformation2.isSelected()) {
                    getChildFragmentManager().beginTransaction()
                            .replace(R.id.ly_information_container, jxDynamicFragment)
                            .commit();
                    tabInformation0.setSelected(false);
                    tabInformation1.setSelected(false);
                    tabInformation2.setSelected(true);
                    tabInformation3.setSelected(false);
                    tabInformation4.setSelected(false);
                    tabInformation5.setSelected(false);
                    tabInformation6.setSelected(false);
                    tabInformation7.setSelected(false);
                }
            }
        });

        tabInformation3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!tabInformation3.isSelected()) {
                    getChildFragmentManager().beginTransaction()
                            .replace(R.id.ly_information_container, qwDynamicFragment)
                            .commit();
                    tabInformation0.setSelected(false);
                    tabInformation1.setSelected(false);
                    tabInformation2.setSelected(false);
                    tabInformation3.setSelected(true);
                    tabInformation4.setSelected(false);
                    tabInformation5.setSelected(false);
                    tabInformation6.setSelected(false);
                    tabInformation7.setSelected(false);
                }
            }
        });

        tabInformation4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!tabInformation4.isSelected()) {
                    getChildFragmentManager().beginTransaction()
                            .replace(R.id.ly_information_container, pictureNewsFragment)
                            .commit();
                    tabInformation0.setSelected(false);
                    tabInformation1.setSelected(false);
                    tabInformation2.setSelected(false);
                    tabInformation3.setSelected(false);
                    tabInformation4.setSelected(true);
                    tabInformation5.setSelected(false);
                    tabInformation6.setSelected(false);
                    tabInformation7.setSelected(false);
                }
            }
        });
        tabInformation5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!tabInformation5.isSelected()) {
                    getChildFragmentManager().beginTransaction()
                            .replace(R.id.ly_information_container, videoNewsFragment)
                            .commit();
                    tabInformation0.setSelected(false);
                    tabInformation1.setSelected(false);
                    tabInformation2.setSelected(false);
                    tabInformation3.setSelected(false);
                    tabInformation4.setSelected(false);
                    tabInformation5.setSelected(true);
                    tabInformation6.setSelected(false);
                    tabInformation7.setSelected(false);
                }
            }
        });
        tabInformation6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!tabInformation6.isSelected()) {
                    getChildFragmentManager().beginTransaction()
                            .replace(R.id.ly_information_container, notifyNewsFragment)
                            .commit();
                    tabInformation0.setSelected(false);
                    tabInformation1.setSelected(false);
                    tabInformation2.setSelected(false);
                    tabInformation3.setSelected(false);
                    tabInformation4.setSelected(false);
                    tabInformation5.setSelected(false);
                    tabInformation6.setSelected(true);
                    tabInformation7.setSelected(false);
                }
            }
        });
        tabInformation7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!tabInformation7.isSelected()) {
                    getChildFragmentManager().beginTransaction()
                            .replace(R.id.ly_information_container, announceNewsFragment)
                            .commit();
                    tabInformation0.setSelected(false);
                    tabInformation1.setSelected(false);
                    tabInformation2.setSelected(false);
                    tabInformation3.setSelected(false);
                    tabInformation4.setSelected(false);
                    tabInformation5.setSelected(false);
                    tabInformation6.setSelected(false);
                    tabInformation7.setSelected(true);
                }
            }
        });


    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


}
